// 没使用
import { resetState } from "@/lib/store";
import axios from "axios";
import { redirect } from "next/navigation";
import toast from "react-hot-toast";

const BaseURL = "http://localhost:8080/";

const instance = axios.create({
    // baseURL: BaseURL,
    headers: {
        'Content-Type': 'application/json'
    }
})


const isCodeMessage = async (response: Response) => {
    let data = null
    if (response.ok) {
        data = await response.json()
        if (data.code < 0) {
            toast.error(data.message)
            resetState()
            return redirect('/login')
        }
    } else {
        toast.dismiss()
        toast.error("未授权请重新登录")
        resetState()
        return redirect('/login')
    }
    return data
}

export {
    BaseURL,
    instance,
    isCodeMessage
}

